#encoding: utf-8
import os , sys
import tornado.websocket 

from handlers.configs import ConfigScene
from handlers.entity import gameScene

'''
{
	**msg_player_move**  		--玩家移动

		return {
			rtype = bool,			--服务器操作是否成功
			data = {
				code = num 		 	--功能操作返回-->注册返回 0正常移动正常
				x = num , 
				y = num 			--移动到的位置
			}

		}
}
'''
'''
{
	**msg_enter_zone**  		--玩家登入场景

		return {
			rtype = bool,			--服务器操作是否成功
			data = {
				code = num 		 	--功能操作返回-->登入正常
			}

		}
}
'''




class zoneHandler(tornado.websocket.WebSocketHandler):

	_waiters = []
	_zonescene = None

	def open(self):
		info('@!Con open! A new comer start to zone')
		if self._zonescene == None:
			self._zonescene = zoneScene()

	def on_close(self , message):
		log("todo  close zonehandler")


	#===================================MSG========================================
	def msg_player_move(self , playerobj , x , y):
		rval = {}
		ret , _x , _y = self._zonescene.dispatch('eventPlayerMove')
		if (ret == True):
			rval['code'] = 0
		else:
			rval['code'] = 1 
		rval['x'] = x
		rval['y'] = y 
		return rval

	def msg_enter_zone(self , playerobj):
		rval = {}
		ret = self._zonescene.dispatch('eventEnter')
		if ret == True:
			rval['code'] = 0
		else:
			rval['code'] = 1 
		return rval